package cn.thoughtworks.school.contract;

import cn.thoughtworks.school.usercenter.Application;
import cn.thoughtworks.school.usercenter.controllers.RegisterController;
import cn.thoughtworks.school.usercenter.entities.NodeBBUser;
import cn.thoughtworks.school.usercenter.repositories.UserRepository;
import cn.thoughtworks.school.usercenter.services.NodeBBUserService;
import cn.thoughtworks.school.usercenter.services.ProgramService;
import com.github.database.rider.core.api.configuration.DBUnit;
import com.github.database.rider.core.api.dataset.DataSet;
import com.github.database.rider.spring.api.DBRider;
import io.restassured.module.mockmvc.RestAssuredMockMvc;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder;

import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doNothing;

@Ignore
@SpringBootTest(classes = Application.class)
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@Slf4j
@DBRider
@DBUnit(caseSensitiveTableNames = true)
@DataSet("register.yml")
public class RegisterBase {

    @MockBean
    private NodeBBUserService nodeBBUserService;

    @MockBean
    private ProgramService programService;

    @Autowired
    private RegisterController registerController;

    @Before
    public void setup() throws Exception {

        NodeBBUser nodeBBUser = new NodeBBUser();
        nodeBBUser.setPassword("Ts2lgMf8u%W@t6L6");
        nodeBBUser.setUserId(1L);
        nodeBBUser.setUsername("zhangsan");

        given(nodeBBUserService.createNodeBBUserByUserId(anyLong()))
                .willReturn(nodeBBUser);

        doNothing().when(programService).joinProgram(anyString(), anyString(), anyLong());

        StandaloneMockMvcBuilder standaloneMockMvcBuilder = MockMvcBuilders.standaloneSetup(registerController);
        RestAssuredMockMvc.standaloneSetup(standaloneMockMvcBuilder);
    }
}
